package com.lmabbe.common.datasources.handle;

import com.lmabbe.common.global.constant.RedisKeyConstant;
import com.lmabbe.common.global.context.TenantBuildContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.data.redis.core.ValueOperations;

/**
 * 加载系统数据
 *
 * @author lmabbe
 */
@Slf4j
public class LoadSystemDateHandle extends InitApplicationHandle {

    public LoadSystemDateHandle(ApplicationContext applicationContext, TenantBuildContext tenantContext) {
        super(applicationContext, tenantContext);
    }

    @Override
    public void handle(InitApplicationContext context) {
        log.info(">>>>>>>>>加载系统数据>>>>>>>");
        ValueOperations<String, Object> stringOperation = applicationContext.getBean(ValueOperations.class);
        stringOperation.set(String.format(RedisKeyConstant.System.Tenant.TENANT_INFO, tenantContext.getTenantId()), tenantContext.getTenantInfo());
        stringOperation.set(String.format(RedisKeyConstant.System.Tenant.TENANT_MINIAPP, tenantContext.getTenantId()), tenantContext.getTenantMiniapps());
        stringOperation.set(String.format(RedisKeyConstant.System.Tenant.TENANT_CLIENT, tenantContext.getTenantId()), tenantContext.getClients());
        stringOperation.set(String.format(RedisKeyConstant.System.Tenant.TENANT_PARAM, tenantContext.getTenantId()), getInitSysParamMapper().all());
        stringOperation.set(String.format(RedisKeyConstant.System.Tenant.TENANT_DICT, tenantContext.getTenantId()), getInitSysDictMapper().all());
    }
}
